package org.example.gateway.controller;

import org.example.gateway.pojo.UpdateWeightDto;
import org.example.gateway.pojo.vo.CommonResult;
import org.example.gateway.pojo.vo.InstanceVo;
import org.example.gateway.service.AppInstanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RestController
@RequestMapping("/app/instance")
public class AppInstanceController {
    @Autowired
    private AppInstanceService instanceService;

    @GetMapping("/list")
    public String list(@RequestParam("appId") Integer appId, ModelMap map) {
        List<InstanceVo> instanceVos = instanceService.queryList(appId);
        map.addAttribute("instanceVOS", instanceVos);
        return "instance";
    }

    @PutMapping("")
    public CommonResult updateWeight(@RequestBody @Validated UpdateWeightDto dto){
        instanceService.updateWeight(dto);
        return CommonResult.success();
    }
}
